package com.project.rfidpage.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.rfidpage.dto.*;
import com.project.rfidpage.entity.IcManu;
import com.project.rfidpage.mapper.IcManuMapper;
import com.project.rfidpage.service.IcManuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IcManuServiceImpl implements IcManuService {

    @Resource
    private IcManuMapper icManuMapper;

    @Override
    @DS("master")
    public List<IcManuDto> getListForPage(IcManuParam param) {
        return icManuMapper.selectListByUid(param);
    }

    @Override
    @DS("master")
    public List<TidLivDto> getLivListForPage(RidLivParam param) {
        return icManuMapper.selectLivListByUid(param);
    }

    @Override
    @DS("master")
    public List<IcManu> getByIcNo(String icno) {
        Example example = new Example(IcManu.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("icno", icno);
        return icManuMapper.selectByExample(example);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insert(IcManu entity) {
        icManuMapper.insert(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void update(IcManu entity, String icnoBefore) {
        Example example = new Example(IcManu.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("icno", icnoBefore);
        icManuMapper.updateByExample(entity, example);
    }

    @Override
    @DS("third")
    public List<TidDailyDto> getDailyListForPage(SearchByRqParam param) {
        return icManuMapper.selectDailyListByUid(param);
    }
}
